#!/bin/bash
RRDPATH=/var/lib/collectd/rrd/`hostname`
IMGPATH=/var/www/html/graphs/imgs
width=500
height=200

rrdtool graph -D -w $width -h $height --start -1h $IMGPATH/all_e0_0.png \
DEF:rx0=$RRDPATH/interface/if_octets-eth0.rrd:rx:AVERAGE \
DEF:tx0=$RRDPATH/interface/if_octets-eth0.rrd:tx:AVERAGE \
AREA:rx0#00DFFF:"rx 10s value" \
LINE2:tx0#FF00FF:"tx 10s value"

rrdtool graph -D -w $width -h $height --start -1d $IMGPATH/all_e0_1.png \
DEF:rx0=$RRDPATH/interface/if_octets-eth0.rrd:rx:AVERAGE:step=60 \
DEF:tx0=$RRDPATH/interface/if_octets-eth0.rrd:tx:AVERAGE:step=60 \
AREA:rx0#00DFFF:"rx 1m average" \
LINE2:tx0#FF00FF:"tx 1m average"

rrdtool graph -D -w $width -h $height --start -1w $IMGPATH/all_e0_2.png \
DEF:rx0=$RRDPATH/interface/if_octets-eth0.rrd:rx:AVERAGE:step=300 \
DEF:tx0=$RRDPATH/interface/if_octets-eth0.rrd:tx:AVERAGE:step=300 \
AREA:rx0#00DFFF:"rx 5m average" \
LINE2:tx0#FF00FF:"tx 5m average"

rrdtool graph -D -w $width -h $height --start -1m $IMGPATH/all_e0_3.png \
DEF:rx0=$RRDPATH/interface/if_octets-eth0.rrd:rx:AVERAGE:step=86400 \
DEF:tx0=$RRDPATH/interface/if_octets-eth0.rrd:tx:AVERAGE:step=86400 \
AREA:rx0#00DFFF:"rx daily average" \
LINE2:tx0#FF00FF:"tx daily average"

rrdtool graph -D -w $width -h $height --start -1y $IMGPATH/all_e0_4.png \
DEF:rx0=$RRDPATH/interface/if_octets-eth0.rrd:rx:AVERAGE:step=86400 \
DEF:tx0=$RRDPATH/interface/if_octets-eth0.rrd:tx:AVERAGE:step=86400 \
AREA:rx0#00DFFF:"rx daily average" \
LINE2:tx0#FF00FF:"tx daily average"

#processes
rrdtool graph -D -w $width -h $height --start -1h $IMGPATH/processes_0.png \
DEF:proc=$RRDPATH/processes/ps_state-running.rrd:value:AVERAGE \
AREA:proc#00DFFF:"processes"

rrdtool graph -D -w $width -h $height --start -1d $IMGPATH/processes_1.png \
DEF:proc=$RRDPATH/processes/ps_state-running.rrd:value:AVERAGE:step=60 \
AREA:proc#00DFFF:"processes 1m average"

rrdtool graph -D -w $width -h $height --start -1w $IMGPATH/processes_2.png \
DEF:proc=$RRDPATH/processes/ps_state-running.rrd:value:AVERAGE:step=300 \
AREA:proc#00DFFF:"processes 5m average"

rrdtool graph -D -w $width -h $height --start -1m $IMGPATH/processes_3.png \
DEF:proc=$RRDPATH/processes/ps_state-running.rrd:value:AVERAGE:step=86400 \
AREA:proc#00DFFF:"processes daily average"

rrdtool graph -D -w $width -h $height --start -1y $IMGPATH/processes_4.png \
DEF:proc=$RRDPATH/processes/ps_state-running.rrd:value:AVERAGE:step=86400 \
AREA:proc#00DFFF:"processes daily average"

#memory
rrdtool graph -D -w $width -h $height --start -1h $IMGPATH/memory_0.png \
DEF:memused=$RRDPATH/memory/memory-used.rrd:value:AVERAGE \
DEF:memfree=$RRDPATH/memory/memory-free.rrd:value:AVERAGE \
DEF:memcached=$RRDPATH/memory/memory-cached.rrd:value:AVERAGE \
LINE1:memused#FF0000:"memory used" \
LINE1:memfree#00FF00:"memory free" \
LINE1:memcached#0000FF:"memory cached"

rrdtool graph -D -w $width -h $height --start -1d $IMGPATH/memory_1.png \
DEF:memused=$RRDPATH/memory/memory-used.rrd:value:AVERAGE:step=60 \
DEF:memfree=$RRDPATH/memory/memory-free.rrd:value:AVERAGE:step=60 \
DEF:memcached=$RRDPATH/memory/memory-cached.rrd:value:AVERAGE:step=60 \
LINE1:memused#FF0000:"memory used 1m average" \
LINE1:memfree#00FF00:"memory free 1m average" \
LINE1:memcached#0000FF:"memory cached 1m average"

rrdtool graph -D -w $width -h $height --start -1w $IMGPATH/memory_2.png \
DEF:memused=$RRDPATH/memory/memory-used.rrd:value:AVERAGE:step=300 \
DEF:memfree=$RRDPATH/memory/memory-free.rrd:value:AVERAGE:step=300 \
DEF:memcached=$RRDPATH/memory/memory-cached.rrd:value:AVERAGE:step=300 \
LINE1:memused#FF0000:"memory used 5m average" \
LINE1:memfree#00FF00:"memory free 5m average" \
LINE1:memcached#0000FF:"memory cached 5m average"

rrdtool graph -D -w $width -h $height --start -1m $IMGPATH/memory_3.png \
DEF:memused=$RRDPATH/memory/memory-used.rrd:value:AVERAGE:step=86400 \
DEF:memfree=$RRDPATH/memory/memory-free.rrd:value:AVERAGE:step=86400 \
DEF:memcached=$RRDPATH/memory/memory-cached.rrd:value:AVERAGE:step=86400 \
LINE1:memused#FF0000:"memory used daily average" \
LINE1:memfree#00FF00:"memory free daily average" \
LINE1:memcached#0000FF:"memory cached daily average"

rrdtool graph -D -w $width -h $height --start -1y $IMGPATH/memory_4.png \
DEF:memused=$RRDPATH/memory/memory-used.rrd:value:AVERAGE:step=86400 \
DEF:memfree=$RRDPATH/memory/memory-free.rrd:value:AVERAGE:step=86400 \
DEF:memcached=$RRDPATH/memory/memory-cached.rrd:value:AVERAGE:step=86400 \
LINE1:memused#FF0000:"memory used daily average" \
LINE1:memfree#00FF00:"memory free daily average" \
LINE1:memcached#0000FF:"memory cached daily average"

#load
rrdtool graph -D -w $width -h $height --start -1h $IMGPATH/load_0.png \
DEF:loads=$RRDPATH/load/load.rrd:shortterm:AVERAGE \
DEF:loadm=$RRDPATH/load/load.rrd:midterm:AVERAGE \
DEF:loadl=$RRDPATH/load/load.rrd:longterm:AVERAGE \
LINE1:loads#FF0000:"load shortterm" \
LINE1:loadm#00FF00:"load midterm" \
LINE1:loadl#0000FF:"load longterm"

rrdtool graph -D -w $width -h $height --start -1d $IMGPATH/load_1.png \
DEF:loads=$RRDPATH/load/load.rrd:shortterm:AVERAGE:step=60 \
DEF:loadm=$RRDPATH/load/load.rrd:midterm:AVERAGE:step=60 \
DEF:loadl=$RRDPATH/load/load.rrd:longterm:AVERAGE:step=60 \
LINE1:loads#FF0000:"load shortterm 1m average" \
LINE1:loadm#00FF00:"load midterm 1m average" \
LINE1:loadl#0000FF:"load longterm 1m average"

rrdtool graph -D -w $width -h $height --start -1w $IMGPATH/load_2.png \
DEF:loads=$RRDPATH/load/load.rrd:shortterm:AVERAGE:step=300 \
DEF:loadm=$RRDPATH/load/load.rrd:midterm:AVERAGE:step=300 \
DEF:loadl=$RRDPATH/load/load.rrd:longterm:AVERAGE:step=300 \
LINE1:loads#FF0000:"load shortterm 5m average" \
LINE1:loadm#00FF00:"load midterm 5m average" \
LINE1:loadl#0000FF:"load longterm 5m average"

rrdtool graph -D -w $width -h $height --start -1m $IMGPATH/load_3.png \
DEF:loads=$RRDPATH/load/load.rrd:shortterm:AVERAGE:step=86400 \
DEF:loadm=$RRDPATH/load/load.rrd:midterm:AVERAGE:step=86400 \
DEF:loadl=$RRDPATH/load/load.rrd:longterm:AVERAGE:step=86400 \
LINE1:loads#FF0000:"load shortterm daily average" \
LINE1:loadm#00FF00:"load midterm daily average" \
LINE1:loadl#0000FF:"load longterm daily average"

rrdtool graph -D -w $width -h $height --start -1y $IMGPATH/load_4.png \
DEF:loads=$RRDPATH/load/load.rrd:shortterm:AVERAGE:step=86400 \
DEF:loadm=$RRDPATH/load/load.rrd:midterm:AVERAGE:step=86400 \
DEF:loadl=$RRDPATH/load/load.rrd:longterm:AVERAGE:step=86400 \
LINE1:loads#FF0000:"load shortterm daily average" \
LINE1:loadm#00FF00:"load midterm daily average" \
LINE1:loadl#0000FF:"load longterm daily average"

#cpu
rrdtool graph -D -w $width -h $height --start -1h $IMGPATH/cpu_0.png \
DEF:cpus=$RRDPATH/cpu-0/cpu-system.rrd:value:AVERAGE \
DEF:cpuu=$RRDPATH/cpu-0/cpu-user.rrd:value:AVERAGE \
DEF:cpui=$RRDPATH/cpu-0/cpu-idle.rrd:value:AVERAGE \
LINE1:cpus#FF0000:"cpu system" \
LINE1:cpuu#00FF00:"cpu user" \
LINE1:cpui#0000FF:"cpu idle"

rrdtool graph -D -w $width -h $height --start -1d $IMGPATH/cpu_1.png \
DEF:cpus=$RRDPATH/cpu-0/cpu-system.rrd:value:AVERAGE:step=60 \
DEF:cpuu=$RRDPATH/cpu-0/cpu-user.rrd:value:AVERAGE:step=60 \
DEF:cpui=$RRDPATH/cpu-0/cpu-idle.rrd:value:AVERAGE:step=60 \
LINE1:cpus#FF0000:"cpu system 1m average" \
LINE1:cpuu#00FF00:"cpu user 1m average" \
LINE1:cpui#0000FF:"cpu idle 1m average"

rrdtool graph -D -w $width -h $height --start -1w $IMGPATH/cpu_2.png \
DEF:cpus=$RRDPATH/cpu-0/cpu-system.rrd:value:AVERAGE:step=300 \
DEF:cpuu=$RRDPATH/cpu-0/cpu-user.rrd:value:AVERAGE:step=300 \
DEF:cpui=$RRDPATH/cpu-0/cpu-idle.rrd:value:AVERAGE:step=300 \
LINE1:cpus#FF0000:"cpu system 5m average" \
LINE1:cpuu#00FF00:"cpu user 5m average" \
LINE1:cpui#0000FF:"cpu idle 5m average"

rrdtool graph -D -w $width -h $height --start -1m $IMGPATH/cpu_3.png \
DEF:cpus=$RRDPATH/cpu-0/cpu-system.rrd:value:AVERAGE:step=86400 \
DEF:cpuu=$RRDPATH/cpu-0/cpu-user.rrd:value:AVERAGE:step=86400 \
DEF:cpui=$RRDPATH/cpu-0/cpu-idle.rrd:value:AVERAGE:step=86400 \
LINE1:cpus#FF0000:"cpu system daily average" \
LINE1:cpuu#00FF00:"cpu user daily average" \
LINE1:cpui#0000FF:"cpu idle daily average"

rrdtool graph -D -w $width -h $height --start -1y $IMGPATH/cpu_4.png \
DEF:cpus=$RRDPATH/cpu-0/cpu-system.rrd:value:AVERAGE:step=86400 \
DEF:cpuu=$RRDPATH/cpu-0/cpu-user.rrd:value:AVERAGE:step=86400 \
DEF:cpui=$RRDPATH/cpu-0/cpu-idle.rrd:value:AVERAGE:step=86400 \
LINE1:cpus#FF0000:"cpu system daily average" \
LINE1:cpuu#00FF00:"cpu user daily average" \
LINE1:cpui#0000FF:"cpu idle daily average"
